<template>
  <div class="My_page">
    <div class="My_title">
      <img class="My_title_bgi" src="../picture/我的 背景图片.png" alt="" />
      <div class="My_info">
        <div class="My_myIcon">
          <img
            class="My_avatar"
            src="../picture/我的  info  登录头像.png"
            alt=""
          />
        </div>

        <div class="My_user">
          <div class="My_name">{{data.username}}</div>
          <div class="My_edit">
            <div class="btn" @click="loginBtn">{{data.buttonname}}</div>
          </div>
        </div>
      </div>
    </div>
    <div class="list">
      <van-grid :column-num="3" :border="false" icon-size="22px">
        <van-grid-item icon="star-o" text=" 我的收藏" border to="/collect" />
        <van-grid-item icon="wap-home-o" text="我的出租" border to="/taxi" />
        <van-grid-item icon="coupon-o" text="看房记录" border to="/login" />
        <van-grid-item icon="photo-o" text="成为房主" border to="/login" />
        <van-grid-item icon="contact" text="个人资料" border to="/login" />
        <van-grid-item icon="service-o" text="联系我们" border to="/login" />
      </van-grid>
    </div>
    <div class="My_ad">
      <img src="../picture/我的  广告图片.png" alt="" />
    </div>
  </div>
</template>

<script>
import { getUserInfo } from "@/api/user";
import { getToken } from "@/utils/storage";
import { removeToken } from "@/utils/storage";
import { Dialog } from "vant";
import { Icon } from 'vant';

export default {
  name: "my-page",
  data() {
    return {
      data: {
        username: "",
        buttonname: "",
      },
    };
  },
  async created() {
    const data = await getUserInfo();
    if(getToken('token')){

      this.data.username = data.body.nickname;
      this.data.buttonname = "退出登录";
    }
  },
  methods: {
    loginBtn() {
     if(getToken()) {
      Dialog
          .confirm({
            title: "拜拜",
            message: "确定退出吗",
          })
          .then(() => {
            this.$router.push("/login");
          })
          .catch(() => {
            // on cancel
          });
       }else{
        this.$router.push("/login");
       }
      
    }
  },
};
</script>

<style lang="less" scoped>
.My_page {
  background: #fff;
  height: 100vh;
}
.My_title {
  min-height: 300px;
  position: relative;
}
.My_title_bgi {
  width: 100%;
}
.My_ad {
  padding-top: 50px;
  width: 100%;
}
.My_avatar {
  width: 100%;
}
.My_info {
  position: absolute;
  background: #fff;
  width: 85%;
  height: 55%;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  box-shadow: 0 0 10px 3px #ddd;
  margin: 50px auto 0;
  padding: 0 20px;
  text-align: center;
  font-size: 13px;
}
.My_myIcon {
  position: relative;
  transform: translateY(-50%);
  border-radius: 50%;
  width: 70px;
  height: 70px;
  border: 5px solid #f5f5f5;
  display: inline-block;
  box-shadow: 0 2px 2px #bdbdbd;
}
.My_user {
  .My_name {
    margin-top: -20px;
    margin-bottom: 10px;
  }
  .My_edit {
    color: #999;
    font-size: 12px;
    margin-top: 25px;
    .btn {
      position: absolute;
      left: 39%;
      width: 70px;
      height: 30px;
      background-color: red;
      line-height: 30px;
      text-align: center;
      color: #fff;
      border-radius: 5px;
    }
  }
}
.list {
  margin-top: 30px;
}
.My_ad {
  display: flex;
  margin-top: 8px;
  justify-content: space-evenly;
  padding-bottom: 8px;
  img {
    width: 93%;
    border-radius: 5px;
    margin-bottom: 10px;
  }
}
</style>
